package com.etime.util;

public class PageUtil {
  private int page;      //当前页页码
  private int rows;       //每页显示条数
  private int index;      //偏移量
  private int countRows;      //总条数
  private int countPages;     //总页数
  private int prevPage;       //当前页的上一页页码
  private int nextPage;       //当前页的下一页页码

  public PageUtil(int page, int rows, int countRows) {
    this.page = page;
    this.rows = rows;
    this.countRows = countRows;
    init_index(page, rows);
    init_countPages(countRows,rows);
    init_prevPage(page);
    init_nextPage(page,this.countPages);
  }

  public void init_prevPage(int page){
    if (page==1){
      this.prevPage = page;
    }
    else {
      this.prevPage = page - 1;
    }
  }

  public void init_nextPage(int page,int countPages){
    if (page==countPages){
      this.nextPage = page;
    }
    else {
      this.nextPage = page + 1;
    }
  }

  public void init_index(int page,int rows){
    this.index = (page-1)*rows;
  }

  public void init_countPages(int countRows,int rows){
    if (countRows%rows==0){
      this.countPages = countRows/rows;
    }
    else {
      this.countPages = countRows/rows+1;
    }
  }

  public int getPage() {
    return page;
  }

  public int getRows() {
    return rows;
  }

  public int getIndex() {
    return index;
  }

  public int getCountRows() {
    return countRows;
  }

  public int getCountPages() {
    return countPages;
  }

  public int getPrevPage() {
    return prevPage;
  }

  public int getNextPage() {
    return nextPage;
  }
}
